package com.mzy.linear_struct;

import java.util.Stack;

/**
 * @Author: codermzy
 * @Date: 2024/03/25/21:42
 * @Description:
 */
public class ArrayStack<T> {
    private final Object[] data;
    private int size;

    private final int capacity;

    public ArrayStack(int capacity) {
        this.data = new Object[capacity];
        this.capacity = capacity;
    }

    public void push(T elem) {
        if (size == capacity) {
            throw new RuntimeException("栈满了");
        }
        data[size++] = elem;
    }

    public T peek() {
        if (size == 0) {
            return null;
        }
        return (T) data[size - 1];
    }

    public T pop() {
        if (size == 0) {
            throw new RuntimeException("栈空了！");
        }
        T elem = (T) data[--size];
        return elem;
    }

    public boolean isEmpty() {
        if (size == 0) {
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        ArrayStack<Integer> stack = new ArrayStack<>(64);


    }
}
